#lang racket
(require "primitives.rkt")
(require "tunn_common.rkt")
(require "tunn_obfs.rkt")
(require "tunn_ssh.rkt")
(require "tunn_ssl.rkt")

;Constructs a Kirisurf tunnel.
(define (make-kiri-tunnel
         lport
         rhost
         rport)
  (define randomport (+ 30000 (random 20000)))
  (define lower-layer (make-ssl-tunnel randomport rhost rport 'sslv3))
  (define higher-layer (make-ssh-tunnel lport "localhost" randomport))
  (define listener (tunnel-listener higher-layer))
  (tunnel
   'kiring
   lport
   rhost
   rport
   listener
   (tunnel-_bytesbox lower-layer)
   (tunnel-_totbytesbox lower-layer)
   (tunnel-_lasttimebox lower-layer)
   (λ()
     (tunnel-close lower-layer)
     (tunnel-close higher-layer))))

(provide (all-defined-out))